# -*- coding: utf-8 -*-
# @Time : 2022/8/5 下午2:25
# @Author : WangYunfei
# @FileName: demo5.py
# @Email: yunfei.wang@innvote.com

"""
当乐网 登陆
5. 使用爬虫结合JavaScript模拟登录PC站点 地址：https://oauth.d.cn/auth/goLogin.html。交付：提供数据和代码截图即可。说明：禁止使用自动化等技术
"""
import execjs
import requests


def rsa_passwd(passwd):
    """
    加密密码
    """
    return execjs.compile(open("./demo5_rsa.js").read()).call("rsa", passwd)


def login(username, password):
    """
    登陆
    """
    url = "https://oauth.d.cn/auth/login"
    params = {
        "display": "web",
        "name": username,
        "pwd": rsa_passwd(password),
        "to": "https://www.d.cn/"
    }
    res = requests.get(url=url, params=params)
    print(res.text)


if __name__ == '__main__':
    user = "17639569679"
    pwd = "lanxiaobai1"
    login(user, pwd)





